const { query } = require('../libs/async-db')
const { verificationToken } = require('./token')
const zb = require('./zhibo8')
const tencent = require('./tencent')

const nbaTeam = {
    /**
     * 获取数据库中的球队列表
     */
    getTeamList: async (q, t) => {
        let sql = '', position = q.position || '', token = t;
        let msg = await verificationToken(token)

        if (msg.code == 0) {
            if (position) {
                sql = `SELECT * FROM team_table WHERE division='${position}';`;
            } else {
                sql = `SELECT * FROM team_table;`;
            }
            return await query(sql, 'nba')
        } else {
            return msg
        }
    },

    /**
     * 获取直播8中的球队列表
     */
    getZB8TeamList: async (t) => {
        let token = t;
        let msg = await verificationToken(token)
        if (msg.code == 0) {
            let data = await zb.getTeam()
            return {
                code: 200,
                data: data,
                msg: 'ok'
            }
        } else {
            return msg
        }
    },

    /**
     * 获取腾讯nba的赛程
     */
    getTencentGameList: async (query, t) => {
        let token = t, startTime = query.startTime, endTime = query.endTime;
        let msg = await verificationToken(token)

        if (msg.code == 0) {
            let data = await tencent.getGameList(startTime, endTime)
            return {
                code: 200,
                data: data.data,
                msg: 'ok'
            }
        } else {
            return msg
        }
    }
}


module.exports = nbaTeam